home *** CD-ROM | disk | FTP | other *** search
/ Cre@te Online 2000 December / Cre@teOnline CD05.iso / MacSoft / XML Instance.sea / XML Instance / Required / plugins / HTMLWindow.jar / horst / HTMLPane.class (.txt) < prev    next >
Encoding:
Java Class File  |  2000-03-18  |  37.2 KB  |  1,456 lines

  1. package horst;
  2.  
  3. import horst.parser.HTMLParser;
  4. import java.awt.AWTEvent;
  5. import java.awt.Color;
  6. import java.awt.Component;
  7. import java.awt.Container;
  8. import java.awt.Cursor;
  9. import java.awt.Dimension;
  10. import java.awt.Font;
  11. import java.awt.FontMetrics;
  12. import java.awt.Frame;
  13. import java.awt.Graphics;
  14. import java.awt.Graphics2D;
  15. import java.awt.Image;
  16. import java.awt.LayoutManager;
  17. import java.awt.Point;
  18. import java.awt.Rectangle;
  19. import java.awt.Shape;
  20. import java.awt.event.InputEvent;
  21. import java.awt.event.KeyEvent;
  22. import java.awt.event.MouseEvent;
  23. import java.awt.event.MouseMotionListener;
  24. import java.awt.geom.AffineTransform;
  25. import java.awt.image.ImageObserver;
  26. import java.awt.print.Book;
  27. import java.awt.print.PageFormat;
  28. import java.awt.print.Paper;
  29. import java.awt.print.Printable;
  30. import java.awt.print.PrinterException;
  31. import java.awt.print.PrinterJob;
  32. import java.io.File;
  33. import java.io.FileOutputStream;
  34. import java.io.IOException;
  35. import java.io.PrintWriter;
  36. import java.io.Reader;
  37. import java.net.URL;
  38. import java.net.URLConnection;
  39. import java.util.Date;
  40. import java.util.Enumeration;
  41. import java.util.EventObject;
  42. import javax.swing.JComponent;
  43. import javax.swing.JOptionPane;
  44. import javax.swing.JPanel;
  45. import javax.swing.JPopupMenu;
  46. import javax.swing.JScrollPane;
  47. import javax.swing.JViewport;
  48. import javax.swing.Scrollable;
  49.  
  50. public class HTMLPane extends JPanel implements Scrollable, MouseMotionListener, Printable {
  51.    protected BusyFlag m_busyflag = new BusyFlag();
  52.    protected HTMLDocument m_document;
  53.    protected HTMLParser m_parser = new HTMLParser();
  54.    protected LayoutInfo m_layoutInfo = new LayoutInfo();
  55.    protected View m_rootView;
  56.    protected ViewFactory m_viewFactory = new ViewFactory();
  57.    protected boolean m_bParsing = false;
  58.    protected HTMLPaneProperties m_props = new HTMLPaneProperties();
  59.    protected HTMLPanePreferences m_preferences = new HTMLPanePreferences();
  60.    protected int m_lastLayoutWidth = -1;
  61.    protected boolean m_bCreatingViews;
  62.    protected boolean m_bLayoutInProgress;
  63.    protected Thread m_parsingThread;
  64.    protected ToolTip m_toolTip = new ToolTip(this, "horst");
  65.    protected boolean m_bPrinting = false;
  66.    private static PrintWriter pwOut;
  67.    private static int indent;
  68.  
  69.    public HTMLPane() {
  70.       ((Component)this).enableEvents(48L);
  71.       ((JComponent)this).setBackground(Color.white);
  72.       ((Container)this).setLayout((LayoutManager)null);
  73.    }
  74.  
  75.    protected void addFloater(View v) {
  76.       this.m_props.m_floaters.addElement(v);
  77.    }
  78.  
  79.    public void addLinkListener(LinkListener l) {
  80.       this.m_props.m_linkListeners.addElement(l);
  81.    }
  82.  
  83.    public void addStatusListener(HTMLPaneStatusListener l) {
  84.       this.m_props.m_statusListeners.addElement(l);
  85.    }
  86.  
  87.    public void back() {
  88.       URL u = this.m_props.m_history.back();
  89.       if (u != null) {
  90.          this.loadPage(u, false);
  91.       }
  92.  
  93.    }
  94.  
  95.    protected boolean beginParsing(Reader r, URL baseURL) {
  96.       this.m_props.m_floaters.removeAllElements();
  97.       this.m_document = null;
  98.       this.m_document = this.createDocument();
  99.       if (this.m_props.m_bIsIFrame || this.m_props.m_bIsFrame) {
  100.          this.m_document.m_bPrintTree = false;
  101.       }
  102.  
  103.       this.m_parser.setCallback(this.m_document);
  104.  
  105.       try {
  106.          this.m_parser.parse(r, baseURL);
  107.          this.m_document.m_baseURL = baseURL;
  108.          return true;
  109.       } catch (IOException e) {
  110.          System.out.println(((Throwable)e).getMessage());
  111.          JOptionPane.showMessageDialog((Component)null, "IOException occurred while parsing!", "Error", 0);
  112.          this.notifyStatusListeners(9, (Object)null);
  113.          return false;
  114.       }
  115.    }
  116.  
  117.    protected boolean beginParsing(URLConnection con) {
  118.       URL u = con.getURL();
  119.       this.m_props.m_floaters.removeAllElements();
  120.       this.m_document = null;
  121.       this.m_document = this.createDocument();
  122.       if (this.m_props.m_bIsIFrame || this.m_props.m_bIsFrame) {
  123.          this.m_document.m_bPrintTree = false;
  124.       }
  125.  
  126.       this.m_parser.setCallback(this.m_document);
  127.  
  128.       try {
  129.          this.m_parser.parse(con);
  130.          u = this.m_document.getURL();
  131.          return true;
  132.       } catch (IOException var3) {
  133.          this.notifyStatusListeners(9, u);
  134.          return false;
  135.       }
  136.    }
  137.  
  138.    public boolean canMoveBack() {
  139.       return this.m_props.m_history.canMoveBack();
  140.    }
  141.  
  142.    public boolean canMoveForward() {
  143.       return this.m_props.m_history.canMoveForward();
  144.    }
  145.  
  146.    public void cancelPrintJob() {
  147.       if (this.m_props.m_printJob != null && !this.m_props.m_printJob.isCancelled()) {
  148.          this.m_props.m_printJob.cancel();
  149.       }
  150.  
  151.    }
  152.  
  153.    protected void clearFocusElement() {
  154.       this.notifyMouseOverLink((URL)null);
  155.       if (this.m_props.m_focusElement != null) {
  156.          this.m_props.m_focusElement.propagateFocus(false);
  157.          this.m_props.m_focusElement = null;
  158.          ((Component)this).repaint();
  159.       }
  160.  
  161.    }
  162.  
  163.    public static void closeLog() {
  164.       if (pwOut != null) {
  165.          pwOut.close();
  166.          pwOut = null;
  167.       }
  168.  
  169.    }
  170.  
  171.    protected HTMLDocument createDocument() {
  172.       return new EditableHTMLDocument(this);
  173.    }
  174.  
  175.    protected void createViews(Element root) {
  176.       if (!this.m_bCreatingViews && !this.m_bLayoutInProgress) {
  177.          this.m_bCreatingViews = true;
  178.          ((Container)this).removeAll();
  179.          this.m_lastLayoutWidth = -1;
  180.          if (this.m_rootView != null) {
  181.             this.m_rootView.flushResources();
  182.             this.m_rootView = null;
  183.          }
  184.  
  185.          if (this.m_props.m_rootElement != null) {
  186.             this.m_props.m_rootElement.flushResources();
  187.             this.m_props.m_rootElement = null;
  188.          }
  189.  
  190.          System.gc();
  191.          this.m_props.m_rootElement = root;
  192.          this.m_rootView = this.m_viewFactory.createView((View)null, this.m_props.m_rootElement, this);
  193.          if (this.m_rootView != null) {
  194.             this.m_rootView.makeChildren(this.m_viewFactory);
  195.             this.notifyStatusListeners(3, this.m_document.getURL());
  196.             this.m_rootView.loadResources();
  197.             this.notifyStatusListeners(9, this.m_document.getURL());
  198.          }
  199.  
  200.          this.m_bCreatingViews = false;
  201.       } else {
  202.          System.out.println("createViews being called with m_bCreatingViews=" + this.m_bCreatingViews + " m_bLayoutInProgress=" + this.m_bLayoutInProgress);
  203.       }
  204.    }
  205.  
  206.    public View elementToView(Element e) {
  207.       return this.m_rootView != null && e != null ? this.m_rootView.elementToView(e) : null;
  208.    }
  209.  
  210.    public void enableDebugMessages(boolean bEnable) {
  211.       Utilities.m_bDebugging = bEnable;
  212.    }
  213.  
  214.    public void enableToolTips(boolean bEnable) {
  215.       this.m_preferences.m_bShowToolTip = bEnable;
  216.    }
  217.  
  218.    private int findFocusElement(Element[] anchors) {
  219.       int idx = -1;
  220.       int i = 0;
  221.  
  222.       for(i = 0; i < anchors.length; ++i) {
  223.          Element elem = anchors[i];
  224.          if (this.m_props.m_focusElement != null && this.m_props.m_focusElement.getType() == 50 && elem == this.m_props.m_focusElement || elem.m_relatedElements.size() > 0 && this.m_props.m_focusElement == elem.m_relatedElements.elementAt(0)) {
  225.             break;
  226.          }
  227.       }
  228.  
  229.       if (i < anchors.length) {
  230.          idx = i;
  231.       }
  232.  
  233.       return idx;
  234.    }
  235.  
  236.    int findText(String text, int lastPos) {
  237.       int pos = -1;
  238.       if (this.m_document != null && this.m_rootView != null) {
  239.          StringBuffer buffer = this.m_document.getTextBuffer();
  240.          String str = buffer.toString().toLowerCase();
  241.          text = text.toLowerCase();
  242.          int save = 0;
  243.          if (lastPos >= 0) {
  244.             save = lastPos + text.length();
  245.             str = str.substring(save, str.length());
  246.          }
  247.  
  248.          int idx = str.indexOf(text);
  249.          if (idx != -1) {
  250.             pos = save + idx;
  251.          }
  252.       }
  253.  
  254.       return pos;
  255.    }
  256.  
  257.    protected ElementViewInfo floaterHitTest(int x, int y) {
  258.       ElementViewInfo info = null;
  259.       Enumeration e = this.m_props.m_floaters.elements();
  260.  
  261.       while(e.hasMoreElements()) {
  262.          View v = (View)e.nextElement();
  263.          info = v.viewToModel(x, y);
  264.          if (info != null) {
  265.             break;
  266.          }
  267.       }
  268.  
  269.       return info;
  270.    }
  271.  
  272.    protected void forceLayout() {
  273.       this.lock();
  274.       JViewport vp = this.getViewport();
  275.       if (vp != null) {
  276.          this.m_lastLayoutWidth = -1;
  277.  
  278.          Component parent;
  279.          for(parent = ((Component)this).getParent(); parent != null && !(parent instanceof JScrollPane); parent = parent.getParent()) {
  280.          }
  281.  
  282.          if (parent != null) {
  283.             ((Container)vp).invalidate();
  284.             parent.validate();
  285.          }
  286.       } else {
  287.          Component parent = ((Component)this).getParent();
  288.          if (parent != null && parent.getSize().width > 0) {
  289.             this.layoutViews(parent.getSize().width);
  290.          }
  291.       }
  292.  
  293.       this.unlock();
  294.    }
  295.  
  296.    public void forward() {
  297.       URL u = this.m_props.m_history.forward();
  298.       if (u != null) {
  299.          this.loadPage(u, false);
  300.       }
  301.  
  302.    }
  303.  
  304.    protected Dimension getBrowserDimension() {
  305.       Component parent = ((Component)this).getParent();
  306.       return parent != null && parent instanceof JViewport ? ((JViewport)parent).getExtentSize() : new Dimension(700, 700);
  307.    }
  308.  
  309.    public HTMLDocument getDocument() {
  310.       return this.m_document;
  311.    }
  312.  
  313.    protected View[] getFloaters() {
  314.       View[] floats = new View[this.m_props.m_floaters.size()];
  315.       this.m_props.m_floaters.copyInto(floats);
  316.       return floats;
  317.    }
  318.  
  319.    public boolean getFramesEnabled() {
  320.       return this.m_preferences.m_bFramesEnabled;
  321.    }
  322.  
  323.    protected HTMLWindow getHTMLWindow() {
  324.       for(Component parent = ((Component)this).getParent(); parent != null; parent = parent.getParent()) {
  325.          if (parent instanceof HTMLWindow) {
  326.             return (HTMLWindow)parent;
  327.          }
  328.       }
  329.  
  330.       return null;
  331.    }
  332.  
  333.    public boolean getIFramesEnabled() {
  334.       return this.m_preferences.m_bIFramesEnabled;
  335.    }
  336.  
  337.    protected ModelInfo getModelInfo(int x, int y) {
  338.       ModelInfo info = new ModelInfo(this);
  339.       if (this.m_rootView != null) {
  340.          info.m_ev = this.floaterHitTest(x, y);
  341.          if (info.m_ev == null) {
  342.             info.m_ev = this.m_rootView.viewToModel(x, y);
  343.          }
  344.  
  345.          if (info.m_ev != null && info.m_ev.m_view.isLink()) {
  346.             String link = (String)info.m_ev.m_elem.getAttribute("href");
  347.             if (link != null) {
  348.                info.target = (String)info.m_ev.m_elem.getAttribute("target");
  349.                if (info.target == null) {
  350.                   Element baseElem = this.m_document.getBaseElement();
  351.                   if (baseElem != null) {
  352.                      info.target = (String)baseElem.getAttribute("target");
  353.                   }
  354.                }
  355.  
  356.                String ref = (String)this.m_rootView.getAttribute("href");
  357.                URL refURL = null;
  358.                if (ref != null) {
  359.                   refURL = Utilities.getURL(ref);
  360.                }
  361.  
  362.                if (refURL != null) {
  363.                   info.url = Utilities.getURL(refURL, link);
  364.                } else {
  365.                   info.url = Utilities.getURL(link);
  366.                }
  367.             }
  368.          }
  369.       }
  370.  
  371.       return info;
  372.    }
  373.  
  374.    public int getNumPages(int pgWidth, int pgHeight) {
  375.       int nPages = this.paginate(pgWidth, pgHeight);
  376.       this.m_layoutInfo.bPaginate = false;
  377.       this.forceLayout();
  378.       return nPages;
  379.    }
  380.  
  381.    public PageFormat getPageFormat() {
  382.       return this.m_props.m_pageFormat;
  383.    }
  384.  
  385.    public int getPageHeight() {
  386.       return this.m_rootView != null ? this.m_rootView.getBounds().height : 0;
  387.    }
  388.  
  389.    public Image getPageImage(int pgNum, int pgWidth, int pgHeight) {
  390.       if (this.m_rootView == null) {
  391.          return null;
  392.       } else {
  393.          Image img = null;
  394.          this.paginate(pgWidth, pgHeight);
  395.          Rectangle b = this.m_rootView.getBounds();
  396.          Frame frame = Utilities.getFrame(this);
  397.          Image offscreen = ((Component)frame).createImage(b.width, this.m_layoutInfo.pageHeight);
  398.          Graphics og = offscreen.getGraphics();
  399.          og.setColor(((Component)this).getBackground());
  400.          og.fillRect(0, 0, offscreen.getWidth((ImageObserver)null), offscreen.getHeight((ImageObserver)null));
  401.          og.setClip(0, 0, b.width, this.m_layoutInfo.pageHeight);
  402.          int y = (pgNum - 1) * (this.m_layoutInfo.pageHeight + this.m_layoutInfo.pageBreakHeight);
  403.          og.translate(0, -y);
  404.          this.renderPage(og);
  405.          this.m_layoutInfo.bPaginate = false;
  406.          this.forceLayout();
  407.          return offscreen;
  408.       }
  409.    }
  410.  
  411.    public int getPageWidth() {
  412.       return this.m_rootView != null ? this.m_rootView.getBounds().width : 0;
  413.    }
  414.  
  415.    protected int getPaneHeight() {
  416.       JViewport jp = this.getViewport();
  417.       return jp != null ? jp.getExtentSize().height : 800;
  418.    }
  419.  
  420.    protected int getPaneWidth() {
  421.       JViewport jp = this.getViewport();
  422.       return jp != null ? jp.getExtentSize().width : 800;
  423.    }
  424.  
  425.    public Dimension getPreferredScrollableViewportSize() {
  426.       return this.m_rootView != null ? new Dimension(this.getPageWidth(), this.getPageHeight()) : new Dimension(2000, 2000);
  427.    }
  428.  
  429.    public Dimension getPreferredSize() {
  430.       this.lock();
  431.       int portWidth = this.getPaneWidth();
  432.       int portHeight = this.getPaneHeight();
  433.       if (this.m_rootView == null && this.m_document != null) {
  434.          Element root = this.m_document.getRootElement();
  435.          if (root != null) {
  436.             this.createViews(root);
  437.          }
  438.       }
  439.  
  440.       if (this.m_rootView == null) {
  441.          this.unlock();
  442.          return new Dimension(portWidth, portHeight);
  443.       } else {
  444.          if (this.m_lastLayoutWidth != portWidth) {
  445.             this.layoutViews(portWidth);
  446.          }
  447.  
  448.          Dimension d = new Dimension(this.m_rootView.getBounds().width, this.m_rootView.getBounds().height);
  449.          this.unlock();
  450.          return d;
  451.       }
  452.    }
  453.  
  454.    public int getPrintingLayoutWidth(int width) {
  455.       return this.m_props.m_printingLayoutWidth;
  456.    }
  457.  
  458.    public boolean getProgressiveDisplay() {
  459.       return this.m_preferences.m_bProgressiveDisplay;
  460.    }
  461.  
  462.    protected Element getRootElement() {
  463.       return this.m_props.m_rootElement;
  464.    }
  465.  
  466.    public int getScrollableBlockIncrement(Rectangle visibleRect, int orientation, int direction) {
  467.       switch (orientation) {
  468.          case 0:
  469.             return visibleRect.width;
  470.          case 1:
  471.             return visibleRect.height;
  472.          default:
  473.             throw new IllegalArgumentException("Invalid orientation: " + orientation);
  474.       }
  475.    }
  476.  
  477.    public boolean getScrollableTracksViewportHeight() {
  478.       return false;
  479.    }
  480.  
  481.    public boolean getScrollableTracksViewportWidth() {
  482.       return false;
  483.    }
  484.  
  485.    public int getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction) {
  486.       switch (orientation) {
  487.          case 0:
  488.             return visibleRect.width / 10;
  489.          case 1:
  490.             return visibleRect.height / 10;
  491.          default:
  492.             throw new IllegalArgumentException("Invalid orientation: " + orientation);
  493.       }
  494.    }
  495.  
  496.    public File getSourceFile(String path) {
  497.       File f = null;
  498.       if (this.m_props.m_loadedPage != null) {
  499.          HTMLParser parser = new HTMLParser();
  500.          f = parser.getSourceFile(this.m_props.m_loadedPage, path);
  501.       }
  502.  
  503.       return f;
  504.    }
  505.  
  506.    protected JViewport getViewport() {
  507.       Component parent = ((Component)this).getParent();
  508.       return parent != null && parent instanceof JViewport ? (JViewport)parent : null;
  509.    }
  510.  
  511.    private void handleTabKey(KeyEvent e) {
  512.       Element[] anchors = this.m_document.getAnchors();
  513.       boolean bUp = (((InputEvent)e).getModifiers() & 1) != 0;
  514.       int idx = this.findFocusElement(anchors);
  515.       if (idx == -1) {
  516.          if (!bUp && anchors.length > 0) {
  517.             this.setAnchorFocus(anchors[0]);
  518.          }
  519.       } else if (bUp && idx > 0) {
  520.          this.setAnchorFocus(anchors[idx - 1]);
  521.       } else if (!bUp && idx < anchors.length - 1) {
  522.          this.setAnchorFocus(anchors[idx + 1]);
  523.       } else {
  524.          this.clearFocusElement();
  525.       }
  526.  
  527.       if (this.m_props.m_focusElement != null) {
  528.          this.scrollToVisible(this.m_props.m_focusElement.m_p0);
  529.       }
  530.  
  531.       ((InputEvent)e).consume();
  532.    }
  533.  
  534.    protected void imageMapHitTest(MouseEvent evt, ModelInfo info) {
  535.       if (info.m_ev.m_elem.getType() == 11 && (info.m_ev.m_elem.isAttributeDefined("ismap") || info.m_ev.m_elem.isAttributeDefined("usemap"))) {
  536.          int x = evt.getX() - (info.m_ev.m_view.getBounds().x + info.m_ev.m_view.m_insets.left);
  537.          int y = evt.getY() - (info.m_ev.m_view.getBounds().y + info.m_ev.m_view.m_insets.top);
  538.          String mapName = (String)info.m_ev.m_elem.getAttribute("usemap");
  539.          if (mapName != null && mapName.length() > 0) {
  540.             while(mapName.charAt(0) == '#' && mapName.length() > 1) {
  541.                mapName = mapName.substring(1);
  542.             }
  543.  
  544.             Enumeration e1 = this.m_document.getMapElements();
  545.  
  546.             while(e1.hasMoreElements()) {
  547.                Element mapElem = (Element)e1.nextElement();
  548.                String name = (String)mapElem.getAttribute("name");
  549.                if (name != null && name.equalsIgnoreCase(mapName)) {
  550.                   Enumeration e = mapElem.getChildren().elements();
  551.  
  552.                   while(e.hasMoreElements()) {
  553.                      Element areaElem = (Element)e.nextElement();
  554.                      if (areaElem.getType() == 50 && areaElem.isAttributeDefined("href")) {
  555.                         String shapeName = (String)areaElem.getAttribute("shape");
  556.                         String coordinates = (String)areaElem.getAttribute("coords");
  557.                         if (coordinates != null) {
  558.                            Shape s = Utilities.createShape(shapeName, coordinates);
  559.                            if (s != null && s.getBounds().contains(x, y)) {
  560.                               URL u = Utilities.getURL(this.m_document.getBaseURL(), (String)areaElem.getAttribute("href"));
  561.                               if (u != null) {
  562.                                  info.url = u;
  563.                               }
  564.  
  565.                               info.target = (String)areaElem.getAttribute("target");
  566.                               return;
  567.                            }
  568.                         }
  569.                      }
  570.                   }
  571.                   break;
  572.                }
  573.             }
  574.          } else {
  575.             String href = (String)info.m_ev.m_elem.getAttribute("href");
  576.             if (href != null) {
  577.                String params = "?" + x + "," + y;
  578.                URL u = Utilities.getURL(href + params);
  579.                if (u != null) {
  580.                   info.url = u;
  581.                }
  582.             }
  583.          }
  584.       }
  585.  
  586.    }
  587.  
  588.    public boolean isPaginated() {
  589.       return this.m_layoutInfo.bPaginate;
  590.    }
  591.  
  592.    protected boolean isTextSelected() {
  593.       return this.m_document != null ? this.m_document.isTextSelected() : false;
  594.    }
  595.  
  596.    protected Rectangle layoutViews(int width) {
  597.       Utilities.debugOut("layoutViews width=" + width + " url=" + this.m_props.m_loadedPage);
  598.       if (this.m_rootView == null) {
  599.          return new Rectangle(0, 0, 0, 0);
  600.       } else if (this.m_bLayoutInProgress) {
  601.          System.out.println("BUG HTMLPANE.layoutViews m_bLayoutInProgress recovering...");
  602.          return new Rectangle(0, 0, 0, 0);
  603.       } else if (this.m_bCreatingViews) {
  604.          System.out.println("BUG HTMLPANE.layoutViews recovering...");
  605.          return new Rectangle(0, 0, 0, 0);
  606.       } else {
  607.          this.m_bLayoutInProgress = true;
  608.          this.notifyStatusListeners(2, this.m_props.m_loadedPage);
  609.          this.m_layoutInfo.clear();
  610.          this.m_props.m_floaters.removeAllElements();
  611.          this.m_document.resetElements();
  612.          this.m_rootView.reset();
  613.          this.m_rootView.layout(0, 0, width, this.m_layoutInfo);
  614.          this.m_rootView.setDimensions(this.getPaneWidth(), this.getPaneHeight());
  615.          this.notifyStatusListeners(9, this.m_props.m_loadedPage);
  616.          this.m_bLayoutInProgress = false;
  617.          this.m_lastLayoutWidth = width;
  618.          return this.m_rootView.getBounds();
  619.       }
  620.    }
  621.  
  622.    public void loadApplets(boolean bLoad) {
  623.       this.m_preferences.m_bLoadApplets = bLoad;
  624.    }
  625.  
  626.    protected void loadImageContent(URL u) {
  627.       this.m_document = this.createDocument();
  628.       this.m_props.m_rootElement = new Element(11);
  629.       this.m_props.m_rootElement.setDocument(this.m_document);
  630.       this.m_props.m_rootElement.setAttribute("src", u.toString());
  631.       this.m_props.m_rootElement.setAttribute("imagecontent", "true");
  632.       this.m_props.m_loadedPage = u;
  633.       this.createViews(this.m_props.m_rootElement);
  634.       this.forceLayout();
  635.       this.notifyStatusListeners(5, this.m_props.m_loadedPage);
  636.    }
  637.  
  638.    public void loadImages(boolean bLoad) {
  639.       this.m_preferences.m_bLoadImages = bLoad;
  640.    }
  641.  
  642.    protected synchronized void loadPage(Reader r, URL baseURL, boolean bAddToHistory) {
  643.       this.m_toolTip.hide();
  644.       this.m_bParsing = true;
  645.       ((Component)this).setCursor(Cursor.getPredefinedCursor(3));
  646.       this.m_parsingThread = new Thread(new ParsingThread(this, r, baseURL, bAddToHistory));
  647.       this.m_parsingThread.start();
  648.    }
  649.  
  650.    protected synchronized void loadPage(URL url, boolean bAddToHistory) {
  651.       if (this.m_document != null) {
  652.          String urlStr = url.toString();
  653.          int idx = urlStr.indexOf("#");
  654.          if (idx != -1) {
  655.             String anchorName = urlStr.substring(idx + 1);
  656.             urlStr = urlStr.substring(0, idx);
  657.             URL newURL = Utilities.getURL(urlStr);
  658.             if (this.m_props.m_loadedPage != null && this.m_props.m_loadedPage.equals(newURL)) {
  659.                Element e = this.m_document.getAnchor(anchorName);
  660.                if (e != null && e.m_p0 >= 0) {
  661.                   this.scrollToPosition(e.m_p0);
  662.                   return;
  663.                }
  664.             }
  665.          }
  666.       }
  667.  
  668.       this.m_toolTip.hide();
  669.       this.m_bParsing = true;
  670.       ((Component)this).setCursor(Cursor.getPredefinedCursor(3));
  671.       this.m_parsingThread = new Thread(new ParsingThread(this, url, bAddToHistory));
  672.       this.m_parsingThread.start();
  673.    }
  674.  
  675.    void lock() {
  676.       this.m_busyflag.getBusyFlag();
  677.    }
  678.  
  679.    public void mouseDragged(MouseEvent e) {
  680.    }
  681.  
  682.    public void mouseMoved(MouseEvent e) {
  683.       Object src = ((EventObject)e).getSource();
  684.       if (src instanceof Component) {
  685.          Component c = (Component)src;
  686.          e.translatePoint(c.getBounds().x, c.getBounds().y);
  687.          this.processMouseMotionEvent(e);
  688.       }
  689.  
  690.    }
  691.  
  692.    protected void notifyMouseOverLink(URL u) {
  693.       String href = "";
  694.       if (u != null) {
  695.          href = u.toString();
  696.       }
  697.  
  698.       Enumeration e = this.m_props.m_linkListeners.elements();
  699.  
  700.       while(e.hasMoreElements()) {
  701.          LinkListener l = (LinkListener)e.nextElement();
  702.          l.mouseOverLink(href);
  703.       }
  704.  
  705.    }
  706.  
  707.    protected boolean notifyMousePressedOverLink(URL u) {
  708.       String href = "";
  709.       if (u != null) {
  710.          href = u.toString();
  711.       }
  712.  
  713.       Enumeration e = this.m_props.m_linkListeners.elements();
  714.  
  715.       while(e.hasMoreElements()) {
  716.          LinkListener l = (LinkListener)e.nextElement();
  717.          boolean bLoad = l.mousePressedOverLink(href);
  718.          if (!bLoad) {
  719.             return false;
  720.          }
  721.       }
  722.  
  723.       return true;
  724.    }
  725.  
  726.    protected boolean notifyStatusListeners(int val, Object info) {
  727.       boolean retVal = true;
  728.       Enumeration e = this.m_props.m_statusListeners.elements();
  729.  
  730.       while(e.hasMoreElements()) {
  731.          HTMLPaneStatusListener l = (HTMLPaneStatusListener)e.nextElement();
  732.          HTMLPaneStatusEvent evt = new HTMLPaneStatusEvent(this, val, info);
  733.          if (!l.statusChanged(evt)) {
  734.             retVal = false;
  735.          }
  736.       }
  737.  
  738.       return retVal;
  739.    }
  740.  
  741.    public void openPage(Reader r, URL baseURL) {
  742.       if (r != null) {
  743.          this.loadPage(r, baseURL, true);
  744.       }
  745.  
  746.    }
  747.  
  748.    public void openPage(URL u) {
  749.       if (u != null) {
  750.          this.loadPage(u, true);
  751.       }
  752.  
  753.    }
  754.  
  755.    public int paginate(int pgWidth, int pgHeight) {
  756.       int nPages = 1;
  757.       if (this.m_rootView != null) {
  758.          this.notifyStatusListeners(2, this.m_props.m_loadedPage);
  759.          this.m_layoutInfo.clear();
  760.          this.m_layoutInfo.bPaginate = true;
  761.          this.m_layoutInfo.pageHeight = pgHeight;
  762.          this.m_layoutInfo.pageWidth = pgWidth;
  763.          this.m_props.m_floaters.removeAllElements();
  764.          this.m_document.resetElements();
  765.          this.m_rootView.reset();
  766.          Rectangle b = this.m_rootView.layout(0, 0, pgWidth, this.m_layoutInfo);
  767.          int start = this.m_layoutInfo.pageHeight;
  768.  
  769.          for(int end = start + this.m_layoutInfo.pageBreakHeight; start < b.y + b.height; end = start + this.m_layoutInfo.pageBreakHeight) {
  770.             ++nPages;
  771.             start = end + this.m_layoutInfo.pageHeight;
  772.          }
  773.  
  774.          ((Component)this).repaint();
  775.       }
  776.  
  777.       return nPages;
  778.    }
  779.  
  780.    public void paint(Graphics g) {
  781.       Rectangle alloc = g.getClipRect();
  782.       Dimension dim = ((Component)this).getSize();
  783.       g.setColor(((Component)this).getBackground());
  784.       g.fillRect(0, 0, dim.width, dim.height);
  785.       if (this.m_rootView != null) {
  786.          this.m_rootView.paint(g, alloc);
  787.          Enumeration e = this.m_props.m_floaters.elements();
  788.  
  789.          while(e.hasMoreElements()) {
  790.             View v = (View)e.nextElement();
  791.             Rectangle r = v.getBounds();
  792.             if (r != null) {
  793.                v.paint(g, r);
  794.             }
  795.          }
  796.  
  797.          this.paintFocusBoxes(g, alloc);
  798.       }
  799.  
  800.       ((JComponent)this).paintChildren(g);
  801.       if (this.m_layoutInfo.bPaginate) {
  802.          Rectangle b = this.m_rootView.getBounds();
  803.          int start = this.m_layoutInfo.pageHeight;
  804.          int end = start + this.m_layoutInfo.pageBreakHeight;
  805.  
  806.          for(int nPage = 1; start < b.y + b.height; end = start + this.m_layoutInfo.pageBreakHeight) {
  807.             g.setColor(Color.blue);
  808.             g.drawString("Y = " + start, 20, start);
  809.             g.drawLine(0, start, 800, start);
  810.             g.drawString("Y = " + end + " Page " + nPage++, 20, end);
  811.             g.drawLine(0, end, 800, end);
  812.             start = end + this.m_layoutInfo.pageHeight;
  813.          }
  814.  
  815.          g.setColor(Color.blue);
  816.          g.drawLine(this.m_layoutInfo.pageWidth, 0, this.m_layoutInfo.pageWidth, 2000);
  817.       }
  818.  
  819.    }
  820.  
  821.    void paintFocusBoxes(Graphics g, Shape alloc) {
  822.       this.m_rootView.paintFocusBox(g, alloc);
  823.       Enumeration e = this.m_props.m_floaters.elements();
  824.  
  825.       while(e.hasMoreElements()) {
  826.          View v = (View)e.nextElement();
  827.          Rectangle r = v.getBounds();
  828.          if (r != null) {
  829.             v.paintFocusBox(g, r);
  830.          }
  831.       }
  832.  
  833.       Enumeration e = this.m_document.getAnchorsEnumeration();
  834.  
  835.       while(e.hasMoreElements()) {
  836.          Element elem = (Element)e.nextElement();
  837.          if (elem.getType() == 50 && elem.getDrawFocusBox()) {
  838.             Element mapElem = this.m_document.getMapElement(elem);
  839.             if (mapElem != null) {
  840.                String mapName = (String)mapElem.getAttribute("name");
  841.                if (mapName != null) {
  842.                   mapName = "#" + mapName;
  843.                   Element imgElem = this.m_document.findElement(11, "usemap", mapName);
  844.                   if (imgElem != null) {
  845.                      View vw = this.m_rootView.elementToView(imgElem);
  846.                      if (vw != null) {
  847.                         String shapeName = (String)elem.getAttribute("shape");
  848.                         String coordinates = (String)elem.getAttribute("coords");
  849.                         if (coordinates != null) {
  850.                            Shape s = Utilities.createShape(shapeName, coordinates);
  851.                            if (s != null) {
  852.                               Rectangle r = s.getBounds();
  853.                               r.x += vw.getBounds().x;
  854.                               r.y += vw.getBounds().y;
  855.                               Utilities.drawFocusBorder(g, r);
  856.                            }
  857.                         }
  858.                      }
  859.                   }
  860.                }
  861.             }
  862.          }
  863.       }
  864.  
  865.    }
  866.  
  867.    public int print(Graphics g, PageFormat pf, int pageIndex) throws PrinterException {
  868.       return pageIndex >= this.m_props.m_printSpecs.m_nPages ? 1 : this.renderToPrinter(g, pf, pageIndex);
  869.    }
  870.  
  871.    void printHeaderFooter(Graphics g, PageFormat pf, int pageIndex) {
  872.       Font oldFont = g.getFont();
  873.       g.setFont(this.m_props.m_printSpecs.m_font);
  874.       FontMetrics fm = g.getFontMetrics();
  875.       int textHeight = fm.getHeight();
  876.       int width = (int)pf.getImageableWidth();
  877.       int height = (int)pf.getImageableHeight();
  878.       int x = (int)pf.getImageableX();
  879.       int y = (int)pf.getImageableY();
  880.       g.setColor(Color.black);
  881.       if (this.m_props.m_printSpecs.m_url != null) {
  882.          g.drawString(this.m_props.m_printSpecs.m_url.toString(), x, y + textHeight);
  883.       }
  884.  
  885.       String pgInfo = "Page " + (pageIndex + 1) + " of " + this.m_props.m_printSpecs.m_nPages;
  886.       g.drawString(pgInfo, x, y + height - textHeight);
  887.       String date = this.m_props.m_printSpecs.m_date.toString();
  888.       int space = width - fm.stringWidth(pgInfo);
  889.       int dateWidth = fm.stringWidth(date);
  890.       if (space > dateWidth + 2) {
  891.          g.drawString(date, x + width - (dateWidth + 2), y + height - textHeight);
  892.       }
  893.  
  894.       g.setFont(oldFont);
  895.    }
  896.  
  897.    public void printPage() {
  898.       this.printPage(true, true, true, true);
  899.    }
  900.  
  901.    public void printPage(boolean bShowDialog, boolean bPrintFooterHeader, boolean bUnderLine, boolean bBackground) {
  902.       if (!this.m_bPrinting && this.m_rootView != null) {
  903.          double imageableWidth = (double)((int)this.m_props.m_pageFormat.getImageableWidth());
  904.          double imageableHeight = (double)((int)this.m_props.m_pageFormat.getImageableHeight());
  905.          this.layoutViews(this.m_props.m_printingLayoutWidth);
  906.          int pageWidth = this.m_rootView.getBounds().width;
  907.          double scaleFactor = imageableWidth / (double)pageWidth;
  908.          int pageHeight = (int)(imageableHeight / scaleFactor);
  909.          int nPages = this.paginate(pageWidth, pageHeight);
  910.          this.m_props.m_printSpecs.m_bPrintFooterHeader = bPrintFooterHeader;
  911.          this.m_props.m_printSpecs.m_nPerPage = 1;
  912.          this.m_props.m_printSpecs.m_pageWidth = pageWidth;
  913.          this.m_props.m_printSpecs.m_pageHeight = pageHeight;
  914.          this.m_props.m_printSpecs.m_pageBreakHeight = this.m_layoutInfo.pageBreakHeight;
  915.          this.m_props.m_printSpecs.m_nPages = nPages;
  916.          this.m_props.m_printSpecs.m_pageFormat = this.m_props.m_pageFormat;
  917.          this.m_props.m_printSpecs.m_date = new Date();
  918.          this.m_props.m_printSpecs.m_url = this.m_props.m_loadedPage;
  919.          this.m_props.m_printSpecs.bUnderLineLinks = bUnderLine;
  920.          this.m_props.m_printSpecs.bDisplayBkgndImage = bBackground;
  921.          this.m_props.m_printJob = PrinterJob.getPrinterJob();
  922.          String name = "HTMLWindow";
  923.          if (this.m_props.m_printSpecs.m_url != null) {
  924.             name = name + " - " + this.m_props.m_printSpecs.m_url.toString();
  925.          }
  926.  
  927.          this.m_props.m_printJob.setJobName(name);
  928.          PageFormat pf = (PageFormat)this.m_props.m_pageFormat.clone();
  929.          Paper pr = pf.getPaper();
  930.          pr.setImageableArea(8.351999999999999, 8.351999999999999, 595.2959999999999, 744.0479999999999);
  931.          pf.setPaper(pr);
  932.          Book bk = new Book();
  933.          bk.append(this, pf, this.m_props.m_printSpecs.m_nPages);
  934.          this.m_props.m_printJob.setPageable(bk);
  935.          boolean bPrint = true;
  936.          if (bShowDialog) {
  937.             bPrint = this.m_props.m_printJob.printDialog();
  938.          }
  939.  
  940.          if (!bPrint) {
  941.             this.m_layoutInfo.bPaginate = false;
  942.             this.forceLayout();
  943.          } else {
  944.             try {
  945.                this.m_props.m_printJob.print();
  946.             } catch (Exception e) {
  947.                System.out.println("exception: " + ((Throwable)e).getMessage());
  948.                ((Throwable)e).printStackTrace();
  949.             } finally {
  950.                this.m_layoutInfo.bPaginate = false;
  951.                this.forceLayout();
  952.             }
  953.  
  954.          }
  955.       }
  956.    }
  957.  
  958.    private void printViewTree(View v, int index) {
  959.       String indent = "";
  960.  
  961.       for(int i = 0; i < index; ++i) {
  962.          indent = indent + ' ';
  963.       }
  964.  
  965.       String name = v.getClass().getName();
  966.       toLog(indent + name, 0);
  967.       index += 2;
  968.       int cnt = v.m_children.length;
  969.  
  970.       for(int i = 0; i < cnt; ++i) {
  971.          this.printViewTree(v.m_children[i], index);
  972.       }
  973.  
  974.    }
  975.  
  976.    protected void processKeyEvent(KeyEvent e) {
  977.       if (this.m_rootView != null) {
  978.          if (((AWTEvent)e).getID() == 401 && e.getKeyCode() == 9) {
  979.             this.handleTabKey(e);
  980.          } else if (((AWTEvent)e).getID() == 401 && e.getKeyCode() == 40) {
  981.             this.scrollScreen(true);
  982.          } else if (((AWTEvent)e).getID() == 401 && e.getKeyCode() == 38) {
  983.             this.scrollScreen(false);
  984.          } else if (((AWTEvent)e).getID() == 401 && e.getKeyCode() == 36 && (((InputEvent)e).getModifiers() & 2) != 0) {
  985.             ((JComponent)this).scrollRectToVisible(new Rectangle(0, 0, 1, 1));
  986.          } else if (((AWTEvent)e).getID() == 401 && e.getKeyCode() == 35 && (((InputEvent)e).getModifiers() & 2) != 0) {
  987.             ((JComponent)this).scrollRectToVisible(new Rectangle(0, this.m_rootView.getBounds().y + this.m_rootView.getBounds().height - 1, 1, 1));
  988.          } else if (((AWTEvent)e).getID() == 401 && e.getKeyCode() == 10) {
  989.             if (this.m_props.m_focusElement != null && this.m_props.m_focusElement.isLink()) {
  990.                URL u = Utilities.getURL(this.m_document.getBaseURL(), (String)this.m_props.m_focusElement.getAttribute("href"));
  991.                if (u != null) {
  992.                   this.loadPage(u, true);
  993.                }
  994.             }
  995.  
  996.             ((InputEvent)e).consume();
  997.          }
  998.  
  999.       }
  1000.    }
  1001.  
  1002.    protected void processMouseEvent(MouseEvent evt) {
  1003.       if (this.m_document != null && !this.m_bParsing) {
  1004.          super.processMouseEvent(evt);
  1005.          int x = evt.getX();
  1006.          int y = evt.getY();
  1007.          if (((AWTEvent)evt).getID() == 501) {
  1008.             ((JComponent)this).requestFocus();
  1009.          }
  1010.  
  1011.          if (evt.isPopupTrigger() && this.m_props.m_loadedPage != null) {
  1012.             if (this.notifyStatusListeners(8, this.m_props.m_loadedPage)) {
  1013.                this.m_props.m_popup.show(this, x, y);
  1014.             }
  1015.          } else if (((AWTEvent)evt).getID() == 501 && (((InputEvent)evt).getModifiers() & 16) > 0) {
  1016.             if (this.m_props.m_popup != null && this.m_props.m_popup.isShowing()) {
  1017.                this.m_props.m_popup.setVisible(false);
  1018.             }
  1019.  
  1020.             this.m_document.unSelectText();
  1021.             ModelInfo info = this.getModelInfo(x, y);
  1022.             if (info.m_ev != null && info.m_ev.m_elem != null) {
  1023.                this.m_document.m_selectedP0 = info.m_ev.m_elem.m_textbufferPosition;
  1024.             }
  1025.  
  1026.             this.clearFocusElement();
  1027.             if (info.url != null) {
  1028.                this.notifyMouseOverLink(info.url);
  1029.                this.m_props.m_focusElement = info.m_ev.m_elem;
  1030.                this.m_props.m_focusElement.propagateFocus(true);
  1031.             }
  1032.  
  1033.             ((Component)this).repaint();
  1034.          } else if (((AWTEvent)evt).getID() == 502 && (((InputEvent)evt).getModifiers() & 16) > 0) {
  1035.             ModelInfo info = this.getModelInfo(x, y);
  1036.             if (info.m_ev == null) {
  1037.                return;
  1038.             }
  1039.  
  1040.             this.imageMapHitTest(evt, info);
  1041.             if (info.url != null) {
  1042.                boolean bLoad = false;
  1043.                if (info.url != null) {
  1044.                   bLoad = this.notifyMousePressedOverLink(info.url);
  1045.                }
  1046.  
  1047.                if (bLoad && this.m_props.m_bIsFrame && this.m_props.m_framesetView != null && info.target != null) {
  1048.                   HTMLPane pane = this.m_props.m_framesetView.getFrame(info.target);
  1049.                   if (pane != null) {
  1050.                      pane.loadPage(info.url, false);
  1051.                      ((Component)pane).repaint();
  1052.                      return;
  1053.                   }
  1054.  
  1055.                   for(Container parent = ((Component)this).getParent(); parent != null; parent = ((Component)parent).getParent()) {
  1056.                      if (parent instanceof HTMLPane) {
  1057.                         ((HTMLPane)parent).loadPage(info.url, false);
  1058.                         return;
  1059.                      }
  1060.                   }
  1061.                }
  1062.  
  1063.                if (bLoad) {
  1064.                   this.loadPage(info.url, true);
  1065.                }
  1066.             } else if (info.m_ev.m_elem != null && info.m_ev.m_elem.m_textbufferPosition != -1) {
  1067.                this.m_document.m_selectedP1 = info.m_ev.m_elem.m_textbufferPosition;
  1068.                if (this.m_document.m_selectedP0 > this.m_document.m_selectedP1) {
  1069.                   int temp = this.m_document.m_selectedP1;
  1070.                   this.m_document.m_selectedP1 = this.m_document.m_selectedP0;
  1071.                   this.m_document.m_selectedP0 = temp;
  1072.                }
  1073.  
  1074.                ((Component)this).repaint();
  1075.             }
  1076.  
  1077.             this.clearFocusElement();
  1078.          }
  1079.  
  1080.       }
  1081.    }
  1082.  
  1083.    protected void processMouseMotionEvent(MouseEvent evt) {
  1084.       if (!this.m_bParsing) {
  1085.          super.processMouseMotionEvent(evt);
  1086.          ModelInfo info = this.getModelInfo(evt.getX(), evt.getY());
  1087.          if (info != null && info.m_ev != null && info.m_ev.m_elem != null && info.m_ev.m_view != null) {
  1088.             this.imageMapHitTest(evt, info);
  1089.             boolean bDragging = ((AWTEvent)evt).getID() == 506 && (((InputEvent)evt).getModifiers() & 16) > 0;
  1090.             if (bDragging && this.m_document != null && info.m_ev.m_elem.m_textbufferPosition != -1) {
  1091.                if (this.m_document.m_selectedP0 == -1) {
  1092.                   this.m_document.m_selectedP0 = info.m_ev.m_elem.m_textbufferPosition;
  1093.                } else {
  1094.                   this.m_document.m_selectedP1 = info.m_ev.m_elem.m_textbufferPosition;
  1095.                }
  1096.  
  1097.                if (this.m_document.isTextSelected()) {
  1098.                   ((Component)this).repaint();
  1099.                }
  1100.             }
  1101.  
  1102.             this.m_toolTip.hide();
  1103.             if (this.m_preferences.m_bShowToolTip) {
  1104.                String tipText = info.m_ev.m_view.getToolTipText();
  1105.                if (tipText != null && !Utilities.isBlankSpaces(tipText)) {
  1106.                   Point p = ((Component)this).getLocationOnScreen();
  1107.                   this.m_toolTip.text = tipText;
  1108.                   this.m_toolTip.setLocation(p.x + evt.getX() + 15, p.y + evt.getY() + 15);
  1109.                   this.m_toolTip.show();
  1110.                }
  1111.             }
  1112.  
  1113.             if (info.m_ev.m_view.isLink()) {
  1114.                if (info.url != null) {
  1115.                   this.notifyMouseOverLink(info.url);
  1116.                }
  1117.  
  1118.                ((Component)this).setCursor(Cursor.getPredefinedCursor(12));
  1119.             } else if (info.m_ev.m_elem.getType() == 9) {
  1120.                ((Component)this).setCursor(Cursor.getPredefinedCursor(2));
  1121.             } else {
  1122.                ((Component)this).setCursor(Cursor.getPredefinedCursor(0));
  1123.             }
  1124.  
  1125.          }
  1126.       }
  1127.    }
  1128.  
  1129.    public void reLoadPage() {
  1130.       if (this.m_props.m_loadedPage != null) {
  1131.          this.loadPage(this.m_props.m_loadedPage, false);
  1132.       }
  1133.  
  1134.    }
  1135.  
  1136.    public void removeLinkListener(LinkListener l) {
  1137.       this.m_props.m_linkListeners.removeElement(l);
  1138.    }
  1139.  
  1140.    public void removePagination() {
  1141.       this.m_layoutInfo.bPaginate = false;
  1142.       this.forceLayout();
  1143.    }
  1144.  
  1145.    public void removeStatusListener(HTMLPaneStatusListener l) {
  1146.       this.m_props.m_statusListeners.removeElement(l);
  1147.    }
  1148.  
  1149.    void renderPage(Graphics g) {
  1150.       this.m_rootView.paint(g, g.getClipRect());
  1151.  
  1152.       try {
  1153.          ((JComponent)this).paintChildren(g);
  1154.       } catch (IllegalArgumentException var5) {
  1155.          System.out.println("IllegalArgumentException thrown by a Swing component");
  1156.          System.out.println("HTMLWindow Recovering...");
  1157.       }
  1158.  
  1159.       Enumeration e = this.m_props.m_floaters.elements();
  1160.  
  1161.       while(e.hasMoreElements()) {
  1162.          View v = (View)e.nextElement();
  1163.          Rectangle r = v.getBounds();
  1164.          if (r != null) {
  1165.             v.paint(g, r);
  1166.          }
  1167.       }
  1168.  
  1169.    }
  1170.  
  1171.    int renderToPrinter(Graphics g, PageFormat pf, int pageIndex) throws PrinterException {
  1172.       Graphics2D g2d = (Graphics2D)g;
  1173.       AffineTransform origTfm = g2d.getTransform();
  1174.       g.setClip((int)this.m_props.m_printSpecs.m_pageFormat.getImageableX(), (int)this.m_props.m_printSpecs.m_pageFormat.getImageableY(), (int)this.m_props.m_printSpecs.m_pageFormat.getImageableWidth(), (int)this.m_props.m_printSpecs.m_pageFormat.getImageableHeight());
  1175.       if (this.m_props.m_printSpecs.m_nPerPage == 1) {
  1176.          AffineTransform at = new AffineTransform(origTfm);
  1177.          double scaleFactorX = Math.min((double)1.0F, this.m_props.m_printSpecs.m_pageFormat.getImageableWidth() / (double)this.m_rootView.getBounds().width);
  1178.          double scaleFactorY = Math.min((double)1.0F, this.m_props.m_printSpecs.m_pageFormat.getImageableHeight() / (double)this.m_props.m_printSpecs.m_pageHeight);
  1179.          at.scale(scaleFactorX, scaleFactorY);
  1180.          g2d.setTransform(at);
  1181.          g2d.translate((double)((int)this.m_props.m_printSpecs.m_pageFormat.getImageableX()) / scaleFactorX, (double)((int)this.m_props.m_printSpecs.m_pageFormat.getImageableY()) / scaleFactorY);
  1182.          int yTranslation = (this.m_props.m_printSpecs.m_pageHeight + this.m_props.m_printSpecs.m_pageBreakHeight) * pageIndex;
  1183.          g2d.translate(0, -yTranslation);
  1184.          this.m_props.m_bUnderLineLinks = this.m_props.m_printSpecs.bUnderLineLinks;
  1185.          this.m_props.m_bDisplayBackgroundImage = this.m_props.m_printSpecs.bDisplayBkgndImage;
  1186.          this.m_rootView.paint(g2d, ((Graphics)g2d).getClipRect());
  1187.  
  1188.          try {
  1189.             ((JComponent)this).paintChildren(g2d);
  1190.          } catch (IllegalArgumentException var15) {
  1191.             System.out.println("IllegalArgumentException thrown by a Swing component");
  1192.             System.out.println("HTMLWindow Recovering...");
  1193.          }
  1194.  
  1195.          Enumeration e = this.m_props.m_floaters.elements();
  1196.  
  1197.          while(e.hasMoreElements()) {
  1198.             View v = (View)e.nextElement();
  1199.             Rectangle r = v.getBounds();
  1200.             if (r != null) {
  1201.                v.paint(g, r);
  1202.             }
  1203.          }
  1204.  
  1205.          this.m_props.m_bUnderLineLinks = true;
  1206.          this.m_props.m_bDisplayBackgroundImage = true;
  1207.       }
  1208.  
  1209.       g2d.setTransform(origTfm);
  1210.       ((Graphics)g2d).setClip((int)pf.getImageableX(), (int)pf.getImageableY(), (int)pf.getImageableWidth(), (int)pf.getImageableHeight());
  1211.       if (this.m_props.m_printSpecs.m_bPrintFooterHeader) {
  1212.          this.printHeaderFooter(g, pf, pageIndex);
  1213.       }
  1214.  
  1215.       return 0;
  1216.    }
  1217.  
  1218.    private void scrollScreen(boolean bUp) {
  1219.       HTMLWindow wnd;
  1220.       if (this.m_rootView != null && (wnd = this.getHTMLWindow()) != null) {
  1221.          JViewport vp = this.getViewport();
  1222.          if (vp != null) {
  1223.             Dimension dim = vp.getExtentSize();
  1224.             Point p = vp.getViewPosition();
  1225.             int endY = this.m_rootView.getBounds().y + this.m_rootView.getBounds().height;
  1226.             int increment = dim.height / 10;
  1227.             if (bUp && p.y + dim.height < endY) {
  1228.                int newY = p.y + increment;
  1229.                if (newY > endY) {
  1230.                   newY = endY - dim.height;
  1231.                }
  1232.  
  1233.                wnd.scrollToYPosition(newY);
  1234.             } else if (!bUp && p.y > 0) {
  1235.                int newY = Math.max(0, p.y - increment);
  1236.                wnd.scrollToYPosition(newY);
  1237.             }
  1238.          }
  1239.       }
  1240.  
  1241.    }
  1242.  
  1243.    private void scrollToPosition(int pos) {
  1244.       for(Component parent = ((Component)this).getParent(); parent != null; parent = parent.getParent()) {
  1245.          if (parent instanceof HTMLWindow) {
  1246.             ((HTMLWindow)parent).scrollToPosition(pos);
  1247.             return;
  1248.          }
  1249.       }
  1250.  
  1251.    }
  1252.  
  1253.    private void scrollToVisible(int pos) {
  1254.       for(Component parent = ((Component)this).getParent(); parent != null; parent = parent.getParent()) {
  1255.          if (parent instanceof HTMLWindow) {
  1256.             ((HTMLWindow)parent).scrollToVisible(pos);
  1257.             return;
  1258.          }
  1259.       }
  1260.  
  1261.    }
  1262.  
  1263.    public void setAlwaysSizableFrames(boolean bSizable) {
  1264.       this.m_preferences.m_bAlwaysSizableFrames = bSizable;
  1265.    }
  1266.  
  1267.    private void setAnchorFocus(Element anchor) {
  1268.       this.clearFocusElement();
  1269.       if (anchor.getType() == 50) {
  1270.          this.m_props.m_focusElement = anchor;
  1271.          anchor.setDrawFocusBox(true);
  1272.       } else {
  1273.          Element[] relates = anchor.getRelatedElements();
  1274.          if (relates.length > 0) {
  1275.             this.m_props.m_focusElement = relates[0];
  1276.             this.m_props.m_focusElement.setDrawFocusBox(true);
  1277.             this.m_props.m_focusElement.propagateDrawFocusBox(true);
  1278.          }
  1279.       }
  1280.  
  1281.       ((Component)this).repaint();
  1282.    }
  1283.  
  1284.    public void setDefaultFont(Font f) {
  1285.       if (f != null) {
  1286.          this.m_props.m_defaultFont = f;
  1287.       }
  1288.  
  1289.    }
  1290.  
  1291.    public void setFramesEnabled(boolean bEnable) {
  1292.       this.m_preferences.m_bFramesEnabled = bEnable;
  1293.    }
  1294.  
  1295.    public void setIFramesEnabled(boolean bEnable) {
  1296.       this.m_preferences.m_bIFramesEnabled = bEnable;
  1297.    }
  1298.  
  1299.    protected void setMargins(int width, int height) {
  1300.       this.m_props.m_marginWidth = width;
  1301.       this.m_props.m_marginHeight = height;
  1302.    }
  1303.  
  1304.    public void setPageFormat(PageFormat pf) {
  1305.       if (pf != null) {
  1306.          this.m_props.m_pageFormat = pf;
  1307.       }
  1308.  
  1309.    }
  1310.  
  1311.    public void setPopupMenu(JPopupMenu menu) {
  1312.       if (this.m_props.m_popup != null) {
  1313.          ((Container)this).remove(this.m_props.m_popup);
  1314.       }
  1315.  
  1316.       this.m_props.m_popup = menu;
  1317.       ((Container)this).add(this.m_props.m_popup);
  1318.    }
  1319.  
  1320.    public void setPrintingLayoutWidth(int width) throws Exception {
  1321.       if (width > 500) {
  1322.          this.m_props.m_printingLayoutWidth = width;
  1323.       } else {
  1324.          throw new Exception("Minimum printing layout width is 500 pixels!");
  1325.       }
  1326.    }
  1327.  
  1328.    public void setProgressiveDisplay(boolean bProgressive) {
  1329.       this.m_preferences.m_bProgressiveDisplay = bProgressive;
  1330.    }
  1331.  
  1332.    public void setSize(Dimension d) {
  1333.       this.lock();
  1334.       if (this.m_rootView != null) {
  1335.          if (d.width != this.m_rootView.getBounds().width) {
  1336.             this.layoutViews(d.width);
  1337.          }
  1338.  
  1339.          super.setSize(this.m_rootView.getBounds().width, this.m_rootView.getBounds().height);
  1340.          this.unlock();
  1341.       } else {
  1342.          super.setSize(d);
  1343.          this.unlock();
  1344.       }
  1345.    }
  1346.  
  1347.    public void setViewFactory(ViewFactory factory) {
  1348.       this.m_viewFactory = factory;
  1349.    }
  1350.  
  1351.    public void stop() {
  1352.       if (this.m_parsingThread != null && this.m_parsingThread.isAlive()) {
  1353.          this.m_parsingThread.interrupt();
  1354.          this.m_parsingThread = null;
  1355.       }
  1356.  
  1357.       ((Component)this).setCursor(Cursor.getPredefinedCursor(0));
  1358.       this.notifyStatusListeners(9, this.m_props.m_loadedPage);
  1359.    }
  1360.  
  1361.    public synchronized void syncOpenPage(URL u) throws IOException {
  1362.       ((Component)this).setCursor(Cursor.getPredefinedCursor(3));
  1363.       this.m_toolTip.hide();
  1364.       URLConnection con = u.openConnection();
  1365.       String contentType = con.getContentType();
  1366.       if (this.notifyStatusListeners(6, contentType)) {
  1367.          this.beginParsing(con);
  1368.          if (this.m_document != null) {
  1369.             Element root = this.m_document.getRootElement();
  1370.             if (root != null) {
  1371.                this.createViews(root);
  1372.                this.m_props.m_loadedPage = this.m_document.getURL();
  1373.                this.notifyStatusListeners(5, this.m_props.m_loadedPage);
  1374.                ((JComponent)this).scrollRectToVisible(new Rectangle(0, 0, 1, 1));
  1375.                if (this.m_props.m_loadedPage != null) {
  1376.                   String urlStr = this.m_props.m_loadedPage.toString();
  1377.                   int idx = urlStr.indexOf("#");
  1378.                   if (idx != -1) {
  1379.                      Element elem = this.m_document.getAnchor(urlStr.substring(idx + 1));
  1380.                      if (elem != null && elem.m_p0 >= 0) {
  1381.                         this.scrollToPosition(elem.m_p0);
  1382.                      }
  1383.                   }
  1384.                }
  1385.  
  1386.                this.forceLayout();
  1387.             }
  1388.          }
  1389.       }
  1390.  
  1391.       ((Component)this).setCursor(Cursor.getPredefinedCursor(0));
  1392.    }
  1393.  
  1394.    public static void toLog(String str, int nIndent) {
  1395.       if (pwOut == null) {
  1396.          try {
  1397.             String dir = System.getProperty("user.dir");
  1398.             FileOutputStream fOut = new FileOutputStream(dir + "\\viewtree.log");
  1399.             pwOut = new PrintWriter(fOut);
  1400.          } catch (IOException e) {
  1401.             ((Throwable)e).printStackTrace();
  1402.          }
  1403.       }
  1404.  
  1405.       if (nIndent > 0) {
  1406.          indent += nIndent;
  1407.       }
  1408.  
  1409.       String identStr = "";
  1410.  
  1411.       for(int i = 0; i < indent; ++i) {
  1412.          identStr = identStr + " ";
  1413.       }
  1414.  
  1415.       pwOut.println(identStr + str);
  1416.       if (nIndent < 0) {
  1417.          indent += nIndent;
  1418.       }
  1419.  
  1420.    }
  1421.  
  1422.    public synchronized void unLoadPage() {
  1423.       ((Container)this).removeAll();
  1424.       this.m_document = null;
  1425.       this.m_rootView = null;
  1426.       this.m_props.m_floaters.removeAllElements();
  1427.       System.gc();
  1428.       ((Component)this).repaint();
  1429.    }
  1430.  
  1431.    void unlock() {
  1432.       this.m_busyflag.freeBusyFlag();
  1433.    }
  1434.  
  1435.    public Element viewToModel(int x, int y) {
  1436.       ElementViewInfo info = this.floaterHitTest(x, y);
  1437.       if (info != null) {
  1438.          return info.m_elem;
  1439.       } else {
  1440.          if (this.m_rootView != null) {
  1441.             info = this.m_rootView.viewToModel(x, y);
  1442.             if (info != null) {
  1443.                return info.m_elem;
  1444.             }
  1445.          }
  1446.  
  1447.          return null;
  1448.       }
  1449.    }
  1450.  
  1451.    // $FF: synthetic method
  1452.    static void access$0(HTMLPane $0, int $1) {
  1453.       $0.scrollToPosition($1);
  1454.    }
  1455. }
  1456.